package com.jz.community.moduleshoppingguide.nearshop.presenter;

import com.jz.community.basecomm.bean.baseGoods.BaseGoodsInfo;
import com.jz.community.basecomm.mvp.BaseLifeCyclePresent;
import com.jz.community.basecomm.net.rxandroid.OnLoadListener;
import com.jz.community.moduleshoppingguide.home.model.ShoppingGuideModel;
import com.jz.community.moduleshoppingguide.home.model.ShoppingModelGuideImpl;
import com.jz.community.moduleshoppingguide.nearshop.bean.GoodsInfo;
import com.jz.community.moduleshoppingguide.nearshop.bean.NearShopCategoryBean;
import com.jz.community.moduleshoppingguide.nearshop.bean.NearShopGoodsRight;
import com.jz.community.moduleshoppingguide.nearshop.bean.ShopInfoBean;
import com.jz.community.moduleshoppingguide.nearshop.model.NearShopModel;
import com.jz.community.moduleshoppingguide.nearshop.model.NearShopModelImp;
import com.jz.community.moduleshoppingguide.nearshop.ui.NearShopGoodsView;

import java.util.List;

public class NearShopGoodsPresenter extends BaseLifeCyclePresent<NearShopGoodsView.View> implements NearShopGoodsView.Presenter {


    private NearShopModel nearShopModel;
    private NearShopGoodsView.View mView;
    private ShoppingGuideModel shoppingModel;


    public NearShopGoodsPresenter(NearShopGoodsView.View view) {
        this.mView = view;
        this.nearShopModel = new NearShopModelImp(view.getContext());
        this.shoppingModel = new ShoppingModelGuideImpl(view.getContext());
    }


    @Override
    public void nearShopInfoes(String shopId) {
        nearShopModel.nearShopInfoes(shopId, new OnLoadListener<ShopInfoBean>() {
            @Override
            public void onSuccess(ShopInfoBean shopInfoBean) {
                mView.showNearShopInfoes(shopInfoBean);
            }

            @Override
            public void onFail(String s, int code) {
                mView.showError(s);
            }
        });
    }

    @Override
    public void getGoodsInfoes(String filter, int page, int size, NearShopGoodsRight goodsRight) {
        shoppingModel.showCategorysGoodsInfoes(filter, page, size, new OnLoadListener<GoodsInfo>() {
            @Override
            public void onSuccess(GoodsInfo baseGoodsInfo) {
                mView.showGoodsInfoes(baseGoodsInfo, goodsRight);
            }

            @Override
            public void onFail(String s, int code) {
                mView.showError(s);
            }
        });
    }

    @Override
    public void getNearShopGoods(int page, int size, String shopId, String categoryId, String name, int type) {
        nearShopModel.getNearShopGoods(page, size, "shopId::" + shopId + "|shopCategoryId::" + categoryId + "|title::" + name, new OnLoadListener<BaseGoodsInfo>() {
            @Override
            public void onSuccess(BaseGoodsInfo goodsInfo) {
                mView.showNearShopGoods(goodsInfo, type);
            }

            @Override
            public void onFail(String msg, int code) {
                mView.showError(msg);
            }
        });
    }

    @Override
    public void nearShopCategory(String shopId) {
        nearShopModel.nearShopCategory(shopId, new OnLoadListener<List<NearShopCategoryBean>>() {
            @Override
            public void onSuccess(List<NearShopCategoryBean> categoryBeanList) {
                mView.showNearShopCategory(categoryBeanList);
            }

            @Override
            public void onFail(String msg, int code) {
                mView.showError(msg);
            }
        });
    }
}
